package com.wen.open.springframework.context.support;

import com.wen.open.springframework.beans.BeansException;
import com.wen.open.springframework.beans.factory.ConfigurableListableBeanFactory;
import com.wen.open.springframework.beans.factory.support.DefaultListableBeanFactory;

/**
 *  实例化bean工厂并注册BeanDefinition
 * @author Wen
 * @date 2023/4/24 16:31
 */
public abstract class AbstractRefreshableApplicationContext extends AbstractApplicationContext{
    private ConfigurableListableBeanFactory beanFactory;

    @Override
    protected void refreshBeanFactory() throws BeansException {
       DefaultListableBeanFactory beanFactory = createBeanFactory();
       loadBeanDefinitions(beanFactory);
       this.beanFactory = beanFactory;
    }

    protected abstract void loadBeanDefinitions(DefaultListableBeanFactory beanFactory);

    private DefaultListableBeanFactory createBeanFactory() {
        return new DefaultListableBeanFactory();
    }

    @Override
    protected ConfigurableListableBeanFactory getBeanFactory() {
        return beanFactory;
    }
}
